home *** CD-ROM | disk | FTP | other *** search
/ Mission 3 / Mission 3.zip / Mission 3.iso / texte / qed / src / projekt.c < prev    next >
C/C++ Source or Header  |  1998-11-09  |  44KB  |  1,970 lines

  1. #include <dirent.h>
  2. #include <keycodes.h>
  3. #include <support.h>
  4. #include <stat.h>
  5. #include <time.h>
  6.  
  7. #include "global.h"
  8. #include "aktion.h"
  9. #include "av.h"
  10. #include "ausgabe.h"
  11. #include "clipbrd.h"
  12. #include "comm.h"
  13. #include "dd.h"
  14. #include "edit.h"
  15. #include "event.h"
  16. #include "kurzel.h"
  17. #include "file.h"
  18. #include "find.h"
  19. #include "icon.h"
  20. #include "memory.h"
  21. #include "menu.h"
  22. #include "options.h"
  23. #include "printer.h"
  24. #include "rsc.h"
  25. #include "set.h"
  26. #include "text.h"
  27. #include "window.h"
  28. #include "projekt.h"
  29.  
  30.  
  31. /* exprortierte Variablen **************************************************/
  32. int        prj_type;
  33. PATH        def_prj_path;
  34.  
  35. /****** DEFINES ************************************************************/
  36.  
  37. #define KIND    (NAME|CLOSER|MOVER|INFO|SIZER|UPARROW|DNARROW|VSLIDE|SMALLER)
  38. #define FLAGS    (WI_FONTSIZE|WI_REDRAW)
  39.  
  40. #define TEMP_LINK 101
  41.  
  42. /****** TYPES **************************************************************/
  43.  
  44. typedef struct            /* für Dreaddir */
  45. {
  46.     long        inode;
  47.     FILENAME name;
  48. } DIRENTRY;
  49.  
  50. /****** VAR ****************************************************************/
  51. static int    do_find_icon;
  52. static PATH    df_path;
  53. static int    def_icon;                        /* Icon für Defaultprojekt */
  54.  
  55. /****** FUNCTIONS **********************************************************/
  56.  
  57. static void    p_icon_exist        (int icon, SET actions);
  58. static bool    p_icon_test            (int icon, int action);
  59. static int    p_icon_edit            (int icon, int action);
  60. static bool    p_icon_drag            (int icon, int source);
  61. static void    draw_line            (WINDOWP window, int line);
  62. static void    wi_draw                (WINDOWP window, GRECT *d);
  63. static void    wi_click             (WINDOWP window, int m_x, int m_y, int bstate, int kstate, int breturn);
  64. static void    wi_unclick            (WINDOWP window);
  65. static bool    wi_key                (WINDOWP window, int kstate, int kreturn);
  66. static void    wi_snap                (WINDOWP window, GRECT *new, int mode);
  67. static void    wi_iconify            (WINDOWP window);
  68. static void    wi_uniconify        (WINDOWP window);
  69. static bool    find_files            (char *pfad, bool rekursiv, char *df_muster, int icon, int tmp_icon);
  70. static void    get_prj_line        (int link, int line, char *str);
  71. static int    del_from_projekt    (int link, int line);
  72. static bool    open_prj             (int icon);
  73. static void    destruct             (int icon);
  74. static void    crt_prj                (WINDOWP window);
  75. static int    crt_new_prj            (char *filename);
  76. static void    info_projekt        (int icon);
  77. static void    select_def_prj     (void);
  78.  
  79. /*****************************************************************************/
  80.  
  81. /*
  82.  * do_for_prj()
  83.  *    bei DO_OPEN, DO_DELETE und Info-Scan -> Aktion auf Projekt selbst
  84. */
  85. static void do_for_prj(int icon, SET s, int (*do_it)(int,int), bool verbose)
  86. {
  87.     TEXTP     t_ptr, t_ptr2;
  88.     ZEILEP     lauf;
  89.     int        min, i, anz, soll, erg;
  90.     PATH        name, prj;
  91.     FILENAME file;
  92.     char        *p;
  93.     
  94.     t_ptr = get_text(icon);
  95.     if (t_ptr->namenlos)
  96.         strcpy(prj, t_ptr->filename);
  97.     else
  98.         file_name(t_ptr->filename, prj, FALSE);
  99.     strcat(prj, ": ");
  100.     p = strrchr(prj, ' ') + 1;                        /* p zeigt auf das Ende */
  101.     
  102.     if (verbose)
  103.     {
  104.         t_ptr2 = get_text(icon);
  105.         if (t_ptr2->namenlos)
  106.             strcpy(file, t_ptr2->filename);
  107.         else
  108.             file_name(t_ptr2->filename,file, FALSE);
  109.         strcpy(p, file);
  110.         start_aktion(prj, TRUE, setcard(s));
  111.     }
  112.  
  113.     min = setmin(s);
  114.     /* So wg. DO_DELETE */
  115.     for (i=setmax(s); i>=min; i--)
  116.     {
  117.         if (setin(s,i))
  118.         {
  119.             lauf = get_line(&t_ptr->text,i);
  120.             lauf->info |= MARKED;
  121.         }
  122.     }
  123.     soll = setcard(s);
  124.     anz = i = 0;
  125.     while (TRUE)
  126.     {
  127.         lauf = get_line(&t_ptr->text,i);
  128.         if (lauf == NULL) 
  129.             break;
  130.         if (IS_MARKED(lauf))
  131.         {
  132.             anz++;
  133.             lauf->info &= (~MARKED);                /* sonst Endlosschleife */
  134.             if (verbose)
  135.             {
  136.                 get_prj_line(icon,i,name);
  137.                 if (name[0] == EOS) 
  138.                     break;
  139.                 file_name(name,file, FALSE);
  140.                 strcpy(p, file);
  141.                 if (!do_aktion(prj, anz))
  142.                 {
  143.                     if (anz < soll && note(1, 2, BREAK) == 1) 
  144.                         break;
  145.                     else
  146.                         redraw_aktion();
  147.                 }
  148.             }
  149.             erg = (*do_it)(icon,i);
  150.             if (erg < 0) 
  151.                 break;
  152.         }
  153.         else
  154.             i++;
  155.     }
  156.     lauf = FIRST(&t_ptr->text);
  157.     while (!IS_TAIL(lauf))
  158.     {
  159.         lauf->info &= (~MARKED);
  160.         NEXT(lauf);
  161.     }
  162.     if (verbose) 
  163.         end_aktion();
  164. }
  165.  
  166. /*
  167.  * bei Sub-Info und Find -> Aktion auf Element(e) des Projekts
  168. */
  169. static bool do_find(int icon);
  170.  
  171. static void do_for_prj2(int icon, SET s, int aktion, bool verbose)
  172. {
  173.     int        i, t_icon, anz, soll, antw;
  174.     TEXTP     t_ptr, t_ptr2;
  175.     PATH        name, prj;
  176.     FILENAME file;
  177.     char        *p;
  178.     
  179.     t_ptr = new_text(TEMP_LINK);                    /* Temp-Text zum Laden der Elemente */
  180.     if (t_ptr == NULL) 
  181.         return;
  182.  
  183.     if (verbose)
  184.     {
  185.         t_ptr2 = get_text(icon);                    /* Name des Projekts ermitteln */
  186.         if (t_ptr2->namenlos)
  187.             strcpy(file, t_ptr2->filename);
  188.         else
  189.             file_name(t_ptr2->filename,file, FALSE);
  190.         
  191.         strcpy(prj, file);
  192.         strcat(prj, ": ");
  193.         p = strrchr(prj, ' ') + 1;                    /* p zeigt auf das Ende */
  194.         strcpy(p, file);
  195.         start_aktion(prj, TRUE, setcard(s));
  196.     }
  197.  
  198.     soll = setcard(s);
  199.     for (i=setmin(s),anz=0; anz<soll; i++)
  200.     {
  201.         if (setin(s,i))
  202.         {
  203.             anz++;
  204.             get_prj_line(icon,i,name);
  205.             if (name[0] == EOS) 
  206.                 break;
  207.             file_name(name, file, FALSE);
  208.  
  209.             t_icon = text_still_loaded(name);
  210.             if (t_icon < 0)
  211.             {
  212.                 set_text_name(t_ptr, name, FALSE);
  213.                 antw = load(t_ptr, FALSE);
  214.                 if (antw != 0)
  215.                     open_error(name, antw);
  216.                 t_icon = TEMP_LINK;            
  217.             }
  218. /*
  219.             do_it(t_icon);
  220. */
  221.             switch (aktion)
  222.             {
  223.                 case DO_INFO :
  224.                     info_edit(t_icon);
  225.                     break;
  226.                 
  227.                 case DO_FIND :
  228.                     t_ptr2 = get_text(t_icon);
  229.                     if ((ff_mask[0] == EOS) || filematch(t_ptr2->filename, ff_mask, t_ptr2->filesys))
  230.                         do_find(t_icon);
  231.                     else
  232.                         file[0] = EOS;            /* nicht in Aktion-Box eintragen! */
  233.                     break;
  234.  
  235.                 default:
  236.                     debug("do_for_prj2(): unbekannte Aktion %d\n", aktion);
  237.                     break;
  238.             }            
  239.  
  240.             if (t_icon == TEMP_LINK) 
  241.                 clear_text(t_ptr);
  242.  
  243.             if (verbose)
  244.             {
  245.                 if (file[0] != EOS)
  246.                     strcpy(p, file);
  247.                 if (!do_aktion(prj, anz))
  248.                 {
  249.                     if (anz < soll && note(1, 2, BREAK) == 1) 
  250.                         break;
  251.                     else
  252.                         redraw_aktion();
  253.                 }
  254.             }
  255.         }
  256.     }
  257.     destruct_text(t_ptr);
  258.     if (verbose)
  259.         end_aktion();
  260. }
  261.  
  262. static bool delete_prj(int icon)
  263. {
  264.     TEXTP     t_ptr = get_text(icon);
  265.     int        antw;
  266.     FILENAME name;
  267.  
  268.     if (t_ptr->moved!=0)
  269.     {
  270.         if (quick_close)
  271.             antw = 1;
  272.         else
  273.         {
  274.             if (t_ptr->namenlos)
  275.                 strcpy(name, t_ptr->filename);
  276.             else
  277.                 file_name(t_ptr->filename, name, FALSE);
  278.             antw = snote(1, 3, MOVED, name);
  279.         }
  280.         if (antw == 1)
  281.         {
  282.             if (do_icon(icon,DO_SAVE)<0)
  283.                 return (FALSE);
  284.         }
  285.         if (antw == 3) 
  286.             return(FALSE);
  287.     }
  288.     return (TRUE);
  289. }
  290.  
  291. static void chg_prj_name(int icon)
  292. {
  293.     WINDOWP         window;
  294.     FILENAME     name;
  295.     TEXTP         t_ptr = get_text(icon);
  296.  
  297.     file_name(t_ptr->filename, name, TRUE);
  298.     window = get_window (icon);
  299.     set_wtitle(window, name);
  300. }
  301.  
  302. /***************************************************************************/
  303. /* Operation vorhanden ?                                                                    */
  304. /***************************************************************************/
  305.  
  306. static void p_icon_exist(int icon, SET actions)
  307. {
  308.     setclr(actions);
  309.     if (icon & SUB_ICON)
  310.     {
  311.         setincl(actions,DO_OPEN);
  312.         setincl(actions,DO_DELETE);
  313.         setincl(actions,DO_INFO);
  314.         setincl(actions,DO_HELP);
  315.     }
  316.     else
  317.     {
  318.         WINDOWP window = get_window(icon);
  319.         TEXTP t_ptr = get_text(icon);
  320.  
  321.         if ((window->flags & WI_ICONIFIED) || (window->flags & WI_SHADED))
  322.         {
  323.             setincl(actions, DO_DELETE);
  324.         }
  325.         else
  326.         {
  327.             if (window->flags & WI_OPEN)
  328.                 setincl(actions, DO_CLOSE);
  329.             setincl(actions, DO_DELETE);
  330.             setincl(actions, DO_SELALL);
  331.             setincl(actions, DO_OPEN);
  332.             setincl(actions, DO_INFO);
  333.             setincl(actions, DO_FIND);
  334.             if (!t_ptr->namenlos)
  335.                 setincl(actions, DO_ABAND);
  336.             setincl(actions, DO_SAVE);
  337.             setincl(actions, DO_SAVENEW);
  338.             setincl(actions, DO_UPDATE);
  339.             setincl(actions, DO_PRINT);
  340.             setincl(actions, DO_HELP);
  341.             setincl(actions, DO_ADD);
  342.             if (t_ptr->moved)
  343.                 setincl(actions, DO_AUTOSAVE);
  344.         }
  345.     }
  346. }
  347.  
  348. /***************************************************************************/
  349. /* Operation testen                                                                            */
  350. /***************************************************************************/
  351.  
  352. static bool p_icon_test(int icon, int action)
  353. {
  354.     bool    erg;
  355.  
  356.     if (icon & SUB_ICON)        /* Aktion auf selektierten Eintrag */
  357.     {
  358.         switch(action)
  359.         {
  360.             case DO_OPEN:    
  361.                 erg = TRUE; 
  362.                 break;
  363.             case DO_DELETE:    
  364.                 erg = TRUE; 
  365.                 break;
  366.             case DO_INFO:    
  367.                 erg = TRUE; 
  368.                 break;
  369.             case DO_HELP:    
  370.                 erg = TRUE; 
  371.                 break;
  372.             default:    
  373.                 erg = FALSE;
  374.         }
  375.     }
  376.     else                            /* Aktion auf Projekt selbst */
  377.     {
  378.         FILENAME name;
  379.         TEXTP     t_ptr = get_text(icon);
  380.  
  381.         switch(action)
  382.         {
  383.             case DO_SELALL:
  384.                 erg = TRUE; 
  385.                 break;
  386.             case DO_CLOSE:
  387.             case DO_DELETE:    
  388.                 erg = delete_prj(icon); 
  389.                 break;
  390.             case DO_OPEN:
  391.                 erg = TRUE; 
  392.                 break;
  393.             case DO_INFO:
  394.                 erg = TRUE; 
  395.                 break;
  396.             case DO_FIND:
  397.                 erg = findfile_dial(t_ptr->filename, TRUE); 
  398.                 break;
  399.             case DO_ABAND:
  400.                 if (t_ptr->namenlos)
  401.                     erg = FALSE;
  402.                 else
  403.                 {
  404.                     erg = TRUE;
  405.                     if (!ist_leer(&t_ptr->text) && t_ptr->moved!=0)
  406.                     {
  407.                         file_name(t_ptr->filename, name, FALSE);
  408.                         erg = (snote(1, 2, ABANDON, name) == 1);
  409.                     }
  410.                 }
  411.                 break;
  412.             case DO_SAVE:
  413.                 erg = TRUE; 
  414.                 break;
  415.             case DO_SAVENEW:
  416.                 erg = TRUE; 
  417.                 break;
  418.             case DO_UPDATE :
  419.                 erg = TRUE; 
  420.                 break;
  421.             case DO_PRINT    :
  422.                 erg = TRUE; 
  423.                 break;
  424.             case DO_HELP    :
  425.                 erg = TRUE; 
  426.                 break;
  427.             case DO_ADD     :
  428.                 erg = findfile_dial(df_path, FALSE);
  429.                 break;
  430.             case DO_AUTOSAVE :
  431.                 if (as_prj && t_ptr->moved)
  432.                 {
  433.                     int    btn;
  434.                     long    min;
  435.  
  436.                     min = (int)((time(NULL) - t_ptr->asave) / 60L);
  437.                     if (min >= as_prj_min)
  438.                     {
  439.                         if (as_prj_ask)                /* Nachfrage ? */
  440.                         {
  441.                             FILENAME     name;
  442.  
  443.                             if (t_ptr->namenlos)
  444.                                 strcpy(name, t_ptr->filename);
  445.                             else
  446.                                 file_name(t_ptr->filename, name, FALSE);
  447.                             Bconout(2, 7);
  448.                             btn = snote(2, 3, ASAVEASK, name);
  449.                             if (btn == 1)
  450.                                 as_prj = FALSE;
  451.                         }
  452.                         else
  453.                             btn = 2;
  454.  
  455.                         t_ptr->asave = time(NULL);
  456.                         erg = (btn == 2);
  457.                     }
  458.                     else
  459.                         erg = FALSE;
  460.                 }
  461.                 else
  462.                 {
  463.                     t_ptr->asave = time(NULL);
  464.                     erg = FALSE;
  465.                 }
  466.                 break;
  467.             default:
  468.                 erg = FALSE;
  469.         }
  470.     }
  471.     return erg;
  472. }
  473.  
  474. /***************************************************************************/
  475. /* Operation durchführen                                                                    */
  476. /***************************************************************************/
  477.  
  478. static int do_open(int prj_icon, int i)
  479. {
  480.     PATH    name;
  481.     int    icon;
  482.     bool    prj;
  483.  
  484.     get_prj_line(prj_icon, i, name);
  485.     prj = filematch(name, "*.QPJ", -1);
  486.     if (prj)
  487.     {
  488.         if (shift_pressed())
  489.             return load_edit(name, FALSE);            /* Laden als Text und öffnen */
  490.         else
  491.             return load_projekt(name);                    /* Laden als Projekt und öffnen */
  492.     }
  493.     else
  494.     {
  495.         icon = load_edit(name, FALSE);                /* Laden als Text und öffnen */
  496.         return icon;
  497.     }
  498. }
  499.  
  500. static bool do_find(int icon)
  501. {
  502.     int    erg = 0;
  503.     TEXTP t_ptr = get_text(icon);
  504.  
  505.     erg = start_find(t_ptr,TRUE);
  506.     if (erg == 1)
  507.         add_to_projekt(do_find_icon, t_ptr->filename, TRUE);
  508.     return (erg != -1);
  509. }
  510.  
  511. static int p_icon_edit(int icon, int action)
  512. {
  513.     PATH    name;
  514.     int    erg;
  515.  
  516.     erg = 0;
  517.     if (icon & SUB_ICON)
  518.     {
  519.         WINDOWP     window;
  520.         SET        help;
  521.  
  522.         icon &= (~SUB_ICON);
  523.         window = get_window(icon);
  524.         if (sel_window==window)
  525.             setcpy(help,sel_objs);
  526.         else
  527.             setclr(help);
  528.         switch (action)
  529.         {
  530.             case DO_OPEN    :
  531.                 do_for_prj(icon,help,do_open,FALSE);
  532.                 break;
  533.             case DO_DELETE    :
  534.                 do_for_prj(icon,help,del_from_projekt,FALSE);
  535.                 break;
  536.             case DO_INFO    :
  537.                 do_for_prj2(icon, help, DO_INFO, FALSE);
  538.                 break;
  539.             case DO_HELP    :
  540.                 erg = call_hyp(rsc_string(HYPPRJSTR));
  541.                 break;
  542.         }
  543.         erg = 1;
  544.     }
  545.     else
  546.     {
  547.         TEXTP     t_ptr = get_text(icon);
  548.         WINDOWP     window = get_window(icon);
  549.         int        i;
  550.         SET        help;
  551.         FILENAME file;
  552.         PATH        h;
  553.  
  554.         switch(action)
  555.         {
  556.             case DO_CLOSE    :
  557.             case DO_DELETE    :
  558.                 if (icon == def_icon)
  559.                 {
  560.                     def_icon = -1;
  561.                     set_def_prj();
  562.                 }
  563.                 destruct(icon);
  564.                 erg = 1;
  565.                 break;
  566.             case DO_SELALL :
  567.                 if (window != sel_window)
  568.                     unclick_window();
  569.                 if (!ist_leer(&t_ptr->text))
  570.                 {
  571.                     sel_window = window;
  572.                     for (i = (int) t_ptr->text.lines; (--i)>=0; )
  573.                         setincl(sel_objs,i);
  574.                     redraw_window(window,&window->work);
  575.                 }
  576.                 erg = 1;
  577.                 break;
  578.             case DO_OPEN    :
  579.                 if (!open_prj (icon))
  580.                     erg = -1;
  581.                 else
  582.                     erg = 1;
  583.                 break;
  584.             case DO_INFO    :
  585.                 info_projekt(icon);
  586.                 erg = 1;
  587.                 break;
  588.             case DO_FIND    :
  589.                 setclr(help);
  590.                 for (i = (int) t_ptr->text.lines; (--i)>=0; )
  591.                     setincl(help,i);
  592.                 do_find_icon = crt_new_prj("");
  593.                 if (do_find_icon < 0)
  594.                     break;
  595.                 if (do_icon(do_find_icon, DO_OPEN) < 0)
  596.                 {
  597.                     note(1, 0, NOWINDOW);
  598.                     icon_edit(icon, DO_DELETE);
  599.                     break;
  600.                 }
  601.                 do_for_prj2(icon, help, DO_FIND, TRUE);
  602.                 t_ptr = get_text(do_find_icon);
  603.                 if (t_ptr->moved)                                    /* etwas gefunden? */
  604.                 {
  605.                     t_ptr->moved = 0;
  606.                     window = get_window(do_find_icon);
  607.                     if (t_ptr->namenlos)
  608.                         strcpy(h, t_ptr->filename);
  609.                     else
  610.                         file_name(t_ptr->filename, h, TRUE);
  611.                     change_window(window, h, FALSE);
  612.                     set_sliders(window, VERTICAL, SLPOS+SLSIZE);
  613.                     redraw_window(window,&window->work);
  614.                 }
  615.                 else
  616.                     icon_edit(do_find_icon, DO_DELETE);    /* wenn nicht, gleich wieder zu */
  617.                 erg = 1;
  618.                 break;
  619.             case DO_ABAND    :
  620.                 strcpy(name, t_ptr->filename);
  621.                 desire_y = window->doc.y+1;
  622.                 close_window(window);
  623.                 destruct_text(t_ptr);
  624.                 del_icon(icon);
  625.                 icon = load_projekt(name);
  626.                 if (icon > 0)
  627.                 {
  628.                     t_ptr = get_text(icon);
  629.                     if (t_ptr!=NULL)
  630.                     {
  631.                         i = (int) (desire_y - window->doc.y);
  632.                         arrow_window(window,WA_DNLINE,i);
  633.                         restore_edit();
  634.                         open_prj(icon);
  635.  
  636.                         memset(msgbuff, 0, (int) sizeof(msgbuff));
  637.                         msgbuff[0] = WM_TOPPED;
  638.                         msgbuff[3] = window->handle;
  639.                         send_msg(gl_apid);
  640.         
  641.                         erg = 1;
  642.                     }
  643.                 }
  644.                 break;
  645.             case DO_SAVE    :
  646.                 if (!t_ptr->namenlos)
  647.                 {
  648.                     if (save(t_ptr) < 0)
  649.                         erg = -1;
  650.                     else
  651.                     {
  652.                         file_name(t_ptr->filename, h, TRUE);
  653.                         change_window(window, h, FALSE);
  654.                         erg = 1;
  655.                     }
  656.                     break;
  657.                 }
  658.                 /* Bei Namenlos zu DO_SAVENEW */
  659.             case DO_SAVENEW:
  660.                 if (!t_ptr->namenlos)
  661.                     strcpy(name, t_ptr->filename);
  662.                 else
  663.                     strcpy(name, "");
  664.                 if (save_new(name, "*.qpj", rsc_string(SAVEPRJSTR)))
  665.                 {
  666.                     set_extension(name,"qpj");
  667.                     if ((erg=save_as(t_ptr,name))==0)
  668.                     {
  669.                         if (t_ptr->namenlos || note(1, 2, GETNAME) == 1)
  670.                         {
  671.                             set_text_name(t_ptr, name, FALSE);
  672.                             chg_prj_name(icon);
  673.                             t_ptr->moved = 0;
  674.                             t_ptr->file_date_time = file_time(name,NULL,NULL);
  675.                             t_ptr->readonly = file_readonly(name);
  676.                         }
  677.                         file_name(t_ptr->filename, h, TRUE);
  678.                         change_window(window, h, FALSE);
  679.                         erg = 1;
  680.                     }
  681.                 }
  682.                 break;
  683.             case DO_UPDATE :
  684.                 redraw_window(window, &window->work);
  685.                 erg = 1;
  686.                 break;
  687.             case DO_PRINT    :
  688.                 if (t_ptr->namenlos)
  689.                     strcpy(file, t_ptr->filename);
  690.                 else
  691.                     file_name(t_ptr->filename, file, FALSE);
  692.                 if (prn_start_dial(NULL))
  693.                     txt_drucken(file,t_ptr);
  694.                 erg = 1;
  695.                 break;
  696.             case DO_HELP    :
  697.                 erg = call_hyp(rsc_string(HYPPRJSTR));
  698.                 break;
  699.             case DO_ADD :
  700.                 if (df_path[0]!=EOS)             /* Pfad durchsuchen */
  701.                 {
  702.                     graf_mouse(HOURGLASS, NULL);
  703.                     strcpy(h, df_path);
  704. /*
  705.                     if (fs_case_sens(df_path) == NO_CASE)
  706.                         str_toupper(ff_mask);
  707. */
  708.                     find_files(h, ff_rekursiv, ff_mask, icon, TEMP_LINK);
  709.                     graf_mouse(ARROW, NULL);
  710.                     redraw_window(window, &window->work);
  711.                 }
  712.                 break;
  713.             case DO_AUTOSAVE:
  714.                 p_icon_edit(icon, DO_SAVE);
  715.                 break;
  716.         }
  717.     }
  718.     return erg;
  719. }
  720.  
  721. /***************************************************************************/
  722. /* Ein Icon wurde auf ein Projekt-Icon geschoben                                    */
  723. /***************************************************************************/
  724.  
  725. static bool p_icon_drag(int icon, int source)
  726. {
  727.     WINDOWP     window = get_window(icon);
  728.     bool    erg = FALSE;
  729.     PATH        h;
  730.  
  731.      if ((window->flags & WI_ICONIFIED) || (window->flags & WI_SHADED))
  732.          return FALSE;
  733.  
  734.     switch (source)
  735.     {
  736.         case DRAGDROP_FILE :
  737.             if (drag_filename[0] != EOS)
  738.             {
  739.                 erg = add_to_projekt(icon, drag_filename, TRUE);
  740.                 drag_filename[0] = EOS;
  741.             }
  742.             break;
  743.         case DRAGDROP_PATH :
  744.             if (drag_filename[0] != EOS)
  745.             {
  746.                 strcpy(df_path, drag_filename);
  747.                 erg = findfile_dial(df_path, FALSE);
  748.                 if (erg)
  749.                 {
  750.                     graf_mouse(HOURGLASS, NULL);
  751.                     strcpy(h, df_path);
  752. /*
  753.                     if (fs_case_sens(df_path) == NO_CASE)
  754.                         str_toupper(ff_mask);
  755. */
  756.                     find_files(h, ff_rekursiv, ff_mask, icon, TEMP_LINK);
  757.                     graf_mouse(ARROW, NULL);
  758.                     redraw_window(window, &window->work);
  759.                 }
  760.                 drag_filename[0] = EOS;
  761.             }
  762.             break;
  763.         case DRAGDROP_DATA :
  764.             Bconout(2, 7);
  765.             erg = FALSE;
  766.             break;
  767.         default:
  768.             if (debug_level)
  769.                 debug("projekt.p_icon_drag(): Unbekannter Mode %d\n", source);
  770.     }
  771.     return erg;
  772. }
  773. /***************************************************************************/
  774.  
  775. /*
  776.  * Dateien für Projekt suchen.
  777.  */
  778. static bool find_files(char *pfad, bool rekursiv, char *df_muster, int icon, int tmp_icon)
  779. {
  780.     TEXTP t_ptr;
  781.     char     *ptr;
  782.     bool    raus;
  783.     int    t_icon;
  784.     PATH    suchPfad;
  785.     DIR    *dh;
  786.  
  787.     if (s_str[0] != EOS)
  788.     {
  789.         t_ptr = new_text(tmp_icon);
  790.         if (t_ptr == NULL) 
  791.             return FALSE;
  792.     }
  793.     strcpy(suchPfad, pfad);
  794.     ptr = pfad + strlen(pfad);
  795.     dh = opendir(suchPfad);
  796.     if (dh != NULL)
  797.     {
  798.         struct dirent    *entry;
  799.         struct stat        st;
  800.  
  801.         do_find_icon = icon;
  802.         if (dh < 0)
  803.             return FALSE;
  804.         raus = FALSE;
  805.         entry = readdir(dh);
  806.         while (entry != NULL && !raus)
  807.         {
  808.             strcpy(ptr, entry->d_name);
  809.             if (stat(pfad, &st) == 0)
  810.             {
  811.                 if ((rekursiv) && (st.st_mode & S_IFDIR) && strcmp(entry->d_name, ".") && strcmp(entry->d_name, ".."))
  812.                 {
  813.                     strcat(ptr, "\\");
  814.                     raus = find_files(pfad, rekursiv, df_muster, icon, tmp_icon + 1);
  815.                 }
  816.  
  817.                 if (!(st.st_mode & S_IFDIR) && filematch(entry->d_name, df_muster, -1))
  818.                 {
  819.                     if (s_str[0] != EOS)
  820.                     {
  821.                         if ((t_icon = text_still_loaded(pfad)) < 0)
  822.                         {
  823.                             set_text_name(t_ptr, pfad, FALSE);
  824.                             if (load(t_ptr, FALSE) < 0)
  825.                                 if (note(2, 0, BREAK) == 1)
  826.                                     break;
  827.                             if (!do_find(tmp_icon))
  828.                                 raus = TRUE;
  829.                             clear_text(t_ptr);
  830.                         }
  831.                         else
  832.                         {
  833.                             if (!do_find(t_icon))
  834.                                 raus = TRUE;
  835.                         }
  836.                     }
  837.                     else
  838.                         add_to_projekt(icon, pfad, TRUE);
  839.                 }
  840.             }
  841.             entry = readdir(dh);
  842.             if (check_for_abbruch() && note(1, 2, BREAK) == 1)
  843.                 raus = TRUE;
  844.         } /* while */
  845.         if (entry != NULL)
  846.             raus = TRUE;
  847.         closedir(dh);
  848.         if (s_str[0] != EOS)
  849.             destruct_text(t_ptr);
  850.         return raus;
  851.     }
  852.     return FALSE;
  853. }
  854.  
  855. /***************************************************************************/
  856.  
  857. static void get_prj_line(int link, int line, char *str)
  858. {
  859.     TEXTP     t_ptr = get_text(link);
  860.     ZEILEP    lauf;
  861.  
  862.     lauf = get_line(&t_ptr->text,line);
  863.     if (lauf != NULL)
  864.         strcpy(str, TEXT(lauf));
  865.     else
  866.         str[0] = EOS;
  867. }
  868.  
  869. /***************************************************************************/
  870.  
  871. static int del_from_projekt (int link, int line)
  872. {
  873.     TEXTP     t_ptr = get_text(link);
  874.     ZEILEP    lauf;
  875.     FILENAME    name;
  876.     
  877.     lauf = get_line(&t_ptr->text,line);
  878.     if (lauf!=NULL)
  879.     {
  880.         WINDOWP window = get_window(link);
  881.  
  882.         unclick_window();
  883.         if (t_ptr->text.lines>1)
  884.         {
  885.             col_delete(&t_ptr->text, lauf);
  886.             window->doc.h--;
  887.             set_sliders(window, VERTICAL, SLPOS+SLSIZE);
  888.             redraw_window(window,&window->work);
  889.         }
  890.         else
  891.         {
  892.             REALLOC(&lauf,0,-lauf->len);
  893.             redraw_window(window,&window->work);
  894.         }
  895.         t_ptr->moved++;
  896.         if (t_ptr->namenlos)
  897.             strcpy(name, t_ptr->filename);
  898.         else
  899.             file_name(t_ptr->filename, name, TRUE);
  900.         change_window(window, name, TRUE);                /* '*' in den Titel */
  901.     }
  902.     return 1;
  903. }
  904.  
  905. bool add_to_projekt (int link, char *name, bool draw)
  906. {
  907.     int        erg, i;
  908.     TEXTP     t_ptr = get_text(link);
  909.     PATH        file;
  910.  
  911. /*
  912.     if (fs_case_sens(name) == NO_CASE)
  913.         str_toupper(name);
  914. */
  915.     strcpy(file,name);
  916. /*
  917.     if (!make_normalpath(file)) 
  918.         return FALSE;
  919. */
  920.     erg = 1; 
  921.     i = 0;
  922.     get_prj_line(link,i,file);
  923.  
  924.     /* Beim Vergleich case-ignore, damit GROSS und klein hintereinander kommen */
  925.     while (file[0] != EOS && (erg = stricmp(file, name)) < 0)
  926.     {
  927.         i++;
  928.         get_prj_line(link,i,file);
  929.     }
  930.     if (erg)             /* noch nicht vorhanden */
  931.     {
  932.         WINDOWP window = get_window(link);
  933.  
  934.         if (ist_leer(&t_ptr->text))
  935.         {
  936.             INSERT(&FIRST(&t_ptr->text),0,(int)strlen(name),name);
  937.             window->doc.h++;
  938.         }
  939.         else
  940.         {
  941.             ZEILEP new, lauf;
  942.  
  943.             if (i==0)
  944.                 lauf = &t_ptr->text.head;
  945.             else
  946.                 lauf= get_line(&t_ptr->text,i-1);
  947.             new = new_col(name,(int)strlen(name));
  948.             col_insert(lauf,new);
  949.             t_ptr->text.lines++;
  950.             window->doc.h++;
  951.             if (draw)
  952.                 set_sliders(window, VERTICAL, SLPOS+SLSIZE);
  953.         }
  954.         if (draw)
  955.             redraw_window(window,&window->work);
  956.         t_ptr->moved++;
  957.         if (t_ptr->namenlos)
  958.             strcpy(file, t_ptr->filename);
  959.         else
  960.             file_name(t_ptr->filename, file, TRUE);
  961.         change_window(window, file, TRUE);                    /* '*' in den Titel */
  962.         return TRUE;
  963.     }
  964.     return FALSE;
  965. }
  966.  
  967. int load_projekt(char *name)
  968. /* return: <=0 wurde nicht geladen */
  969. /*           0    weitere Texte versuchen sinnvoll */
  970. /*           <0    weiter Texte versuchen nicht sinnvoll */
  971. {
  972.     int        err, icon;
  973.     WINDOWP     window;
  974.     FILENAME datei;
  975.     PATH        path;
  976.     TEXTP     t_ptr;
  977.     ZEILEP    lauf;
  978.  
  979.     store_path(name);
  980.  
  981.     split_filename(name, path, datei);
  982.     if ((icon = text_still_loaded(name)) >= 0)    /* schon geladen */
  983.     {
  984.         if (do_icon(icon, DO_OPEN) < 0)                /* nur Fenster auf */
  985.             note(1, 0, NOWINDOW);
  986.         return icon;
  987.     }
  988.     icon = crt_new_prj(name);
  989.     if (icon<0)
  990.     {
  991.         note(1, 0, NOTEXT);
  992.         return -1;
  993.     }
  994.     t_ptr = get_text(icon);;
  995.     if ((err = load(t_ptr, TRUE)) == -33)        /* File not Found */
  996.     {
  997.         if (path_exists(path))
  998.         {
  999.             if (snote(1, 2, NEWTEXT, datei) == 2)
  1000.             {
  1001.                 icon_edit(icon,DO_DELETE);
  1002.                 return 0;
  1003.             }
  1004.         }
  1005.         else
  1006.         {
  1007.             snote(1, 0, READERR, datei);
  1008.             icon_edit(icon,DO_DELETE);
  1009.             return 0;
  1010.         }
  1011.     }
  1012.     else if (err)                                        /* anderer Fehler */
  1013.     {
  1014.         snote(1, 0, READERR, datei);
  1015.         icon_edit(icon,DO_DELETE);
  1016.         return 0;
  1017.     }
  1018.  
  1019.     window = get_window(icon);
  1020.     window->doc.y = 0;
  1021.  
  1022.     /* Zeilenenden säubern */
  1023.     strip_endings(t_ptr);
  1024.     
  1025.     /* Leerzeilen entfernen */
  1026.     lauf = FIRST(&t_ptr->text);
  1027.     while (!IS_TAIL(lauf))
  1028.     {
  1029.         ZEILEP    l = lauf->nachf;
  1030.  
  1031.         if (lauf->len == 0)
  1032.         {
  1033.             col_delete(&t_ptr->text, lauf);
  1034.             t_ptr->moved++;
  1035.         }
  1036.         lauf = l;
  1037.     }
  1038.  
  1039.     if (t_ptr->moved)
  1040.     {
  1041.         file_name(t_ptr->filename, datei, TRUE);
  1042.         change_window(window, datei, TRUE);
  1043.     }
  1044.  
  1045.     window->doc.h = t_ptr->text.lines;
  1046.     if (do_icon(icon,DO_OPEN) < 0)
  1047.     {
  1048.         note(1, 0, NOWINDOW);
  1049.         icon_edit(icon,DO_DELETE);
  1050.         icon = -2;
  1051.     }
  1052.  
  1053.     if (strcmp(name, def_prj_path) == 0)        /* Default-Prj wurde geladen */
  1054.     {
  1055.         def_icon = icon;
  1056.         set_def_prj();
  1057.     }
  1058.     return icon;
  1059. }
  1060.  
  1061. static void destruct(int icon)
  1062. {
  1063.     TEXTP     t_ptr = get_text(icon);
  1064.     WINDOWP     window = get_window(icon);
  1065.  
  1066.     close_window(window);
  1067.     destruct_text(t_ptr);
  1068.     del_icon(icon);
  1069.     do_all_icon(prj_type,DO_UPDATE);     /* Projekte updaten */
  1070. }
  1071.  
  1072. /***************************************************************************/
  1073. /* Anlegen eines neuen Projekts                                                            */
  1074. /***************************************************************************/
  1075.  
  1076. int new_projekt(void)
  1077. {
  1078.     int    icon;
  1079.  
  1080.     icon = crt_new_prj("");
  1081.     if (icon < 0)
  1082.     {
  1083.         note(1, 0,NOTEXT);
  1084.         return -1;
  1085.     }
  1086.     if (do_icon(icon, DO_OPEN) < 0)
  1087.     {
  1088.         note(1, 0, NOWINDOW);
  1089.         icon_edit(icon, DO_DELETE);
  1090.         icon = -3;
  1091.     }
  1092.     return icon;
  1093. }
  1094.  
  1095. int crt_new_prj(char *filename)
  1096. {
  1097.     WINDOWP    win;
  1098.     bool        namenlos;
  1099.     TEXTP     t_ptr;
  1100.     PATH        name;
  1101.  
  1102.     strcpy(name, filename);
  1103.     if (name[0] == EOS)
  1104.     {
  1105.         strcpy(name, rsc_string(NAMENLOS));
  1106.         namenlos = TRUE;
  1107.     }
  1108.     else
  1109.         namenlos = FALSE;
  1110.  
  1111.     /* Fenster anlegen */
  1112.     win = create_window(KIND, CLASS_PROJEKT, crt_prj);
  1113.     if (win == NULL)
  1114.         return -1;
  1115.     if (!add_icon(prj_type, win->handle))
  1116.         return -1;
  1117.  
  1118.     /* Text kreiern */
  1119.     t_ptr = new_text(win->handle);
  1120.     if (t_ptr == NULL)
  1121.     {
  1122.         del_icon(win->handle);
  1123.         return -1;
  1124.     }
  1125.     set_text_name(t_ptr, name, namenlos);
  1126.  
  1127.     if (t_ptr->namenlos)
  1128.         strcpy(name, t_ptr->filename);
  1129.     else
  1130.         file_name(t_ptr->filename, name, TRUE);
  1131.     set_wtitle(win, name);
  1132.     set_winfo(win, "");
  1133.  
  1134.     if (!namenlos)
  1135.         do_all_icon(prj_type,DO_UPDATE);     /* Projekte updaten */
  1136.  
  1137.     t_ptr->asave = time(NULL);
  1138.  
  1139.     return win->handle;
  1140. }
  1141.  
  1142. /***************************************************************************/
  1143. /* Kreieren eines Fensters                                                                 */
  1144. /***************************************************************************/
  1145. static void crt_prj(WINDOWP window)
  1146. {
  1147.     int    initw, inith;
  1148.  
  1149.     if (window->work.g_w == 0 || window->work.g_h == 0)
  1150.     {
  1151.         /* Keine Größe bekannt. */
  1152.         initw  = font_wcell * 13;
  1153.         inith  = (gl_desk.g_h / font_hcell) * font_hcell - 7 * font_hcell;
  1154.         window->work.g_x    = (font_wcell + 2) * 8;
  1155.         window->work.g_y    = 60;
  1156.         window->work.g_w    = initw;
  1157.         window->work.g_h    = inith;
  1158.     }
  1159.     
  1160.     window->flags        = FLAGS;
  1161.     window->doc.w        = 13;
  1162.     window->doc.h        = 0;
  1163.     window->xfac        = font_wcell;
  1164.     window->yfac        = font_hcell;
  1165.     window->w_width    = initw/font_wcell;
  1166.     window->w_height    = inith/font_hcell;
  1167.     window->draw        = wi_draw;
  1168.     window->click        = wi_click;
  1169.     window->unclick    = wi_unclick;
  1170.     window->key         = wi_key;
  1171.     window->snap        = wi_snap;
  1172.     window->iconify    = wi_iconify;
  1173.     window->uniconify = wi_uniconify;
  1174. }
  1175.  
  1176. /***************************************************************************/
  1177. /* Öffnen des Objekts                                                                        */
  1178. /***************************************************************************/
  1179. static bool open_prj (int icon)
  1180. {
  1181.     bool    ok = TRUE;
  1182.     WINDOWP     window = get_window(icon);
  1183.  
  1184.     if (window->flags & WI_ICONIFIED)
  1185.         uniconify_window(window, NULL);
  1186.     else if (window->flags & WI_SHADED)
  1187.         shade_window(window, -1);
  1188.     else if (window->flags & WI_OPEN)
  1189.         top_window (window);
  1190.     else
  1191.         ok = open_window (window);
  1192.     return ok;
  1193. }
  1194.  
  1195. /***************************************************************************/
  1196.  
  1197. static void draw_line (WINDOWP window, int line)
  1198. {
  1199.     TEXTP t_ptr;
  1200.     GRECT    r;
  1201.  
  1202.     t_ptr = get_text(window->handle);
  1203.     if (line >= t_ptr->text.lines) 
  1204.         return;
  1205.     line -= (int)window->doc.y;
  1206.     if (line < 0) 
  1207.         return;
  1208.     if (line>=window->w_height) return;
  1209.     r.g_x = window->work.g_x;
  1210.     r.g_y = window->work.g_y + line * font_hcell;
  1211.     r.g_w = window->work.g_w;
  1212.     r.g_h = font_hcell;
  1213.     redraw_window(window, &r);
  1214. }
  1215.  
  1216. static void wi_draw (WINDOWP window, GRECT *d)
  1217. {
  1218.     ZEILEP lauf;
  1219.     TEXTP t_ptr;
  1220.     int    line, y, x, i, link;
  1221.     PATH    name, str;
  1222.  
  1223.     set_clip(TRUE,d);
  1224.     line = (int)window->doc.y;
  1225.     y = window->work.g_y;
  1226.     x = window->work.g_x;
  1227.     i = window->w_height;
  1228.     if (d->g_y > y)
  1229.     {
  1230.         int anz;
  1231.  
  1232.         anz = (d->g_y - y) / font_hcell;
  1233.         line += anz;
  1234.         y += anz * font_hcell;
  1235.         i -= anz;
  1236.     }
  1237.     if (d->g_y + d->g_h < window->work.g_y + window->work.g_h)
  1238.     {
  1239.         int anz;
  1240.  
  1241.         anz = ((window->work.g_y + window->work.g_h)-(d->g_y + d->g_h)) / font_hcell;
  1242.         i -= anz;
  1243.     }
  1244.     link = window->handle;
  1245.     t_ptr = get_text(link);
  1246.     lauf = get_line(&t_ptr->text,line);
  1247.     if (lauf!=NULL)
  1248.     {
  1249.         while ((--i)>=0)
  1250.         {
  1251.             get_prj_line(link, line, str);
  1252.             if (str[0] == EOS)
  1253.             {
  1254.                 i++;
  1255.                 break;
  1256.             }
  1257.  
  1258.             if (text_still_loaded(str) >= 0) 
  1259.                 name[0] = '*';
  1260.             else 
  1261.                 name[0] = ' ';
  1262.             make_shortpath(str, name + 1, window->w_width - 1);
  1263.             if (window == sel_window && setin(sel_objs,line))
  1264.                 out_sb(x, y, window->work.g_w, name);
  1265.             else
  1266.                 out_s(x, y, window->work.g_w, name);
  1267.             line++;
  1268.             y += font_hcell;
  1269.         }
  1270.     }
  1271.     for (; (--i)>=0; y += font_hcell)
  1272.         fill_line(x, y, window->work.g_w, bg_color);
  1273. }
  1274.  
  1275. /***************************************************************************/
  1276. int drag_box(int x, int y, int w, int h, int *m_x, int *m_y, int *bstate, int *kstate)
  1277. {
  1278.     int    wh, d;
  1279.     
  1280.     graf_mouse(FLAT_HAND, NULL);
  1281.     graf_dragbox(w, h, x, y, gl_desk.g_x, gl_desk.g_y, gl_desk.g_w, gl_desk.g_h, &d, &d);
  1282.     graf_mouse(ARROW, NULL);
  1283.     graf_mkstate(m_x, m_y, bstate, kstate);
  1284.     wh = wind_find(*m_x, *m_y);
  1285.     return wh;
  1286. }
  1287.  
  1288. static void    wi_click (WINDOWP window, int m_x, int m_y, int bstate, int kstate, int breturn)
  1289. {
  1290.     int        y;
  1291.     GRECT        *s = &window->work;
  1292.     PATH        str;
  1293.     SET        new_obj;
  1294.     
  1295.     if (bstate & 2)                                /* Rechtsklick */
  1296.         return;
  1297.  
  1298.     if (!inside(m_x, m_y, s))
  1299.         return;
  1300.  
  1301.     if (sel_window != window)
  1302.         unclick_window();
  1303.     set_winfo(window,"");
  1304.  
  1305.     y = (int)(window->doc.y) + (m_y - s->g_y) / font_hcell;
  1306.     get_prj_line(window->handle, y, str);
  1307.     if (str[0] == EOS)
  1308.         return;
  1309.  
  1310.     setclr(new_obj);
  1311.     setincl(new_obj, y);                                    /* Aktuelles Objekt */
  1312.  
  1313.     if (kstate & (K_RSHIFT|K_LSHIFT))
  1314.     {
  1315.         setxor(sel_objs, new_obj);
  1316.         if (setcmp(sel_objs, NULL))
  1317.             sel_window = NULL;
  1318.         else
  1319.             sel_window = window;
  1320.         draw_line (window, y);
  1321.         if (!setin (sel_objs, y))
  1322.         {
  1323.             graf_mkstate(&m_x, &m_y, &bstate, &kstate);
  1324.             if (bstate & 1)                        /* Immernoch gedrückt ? */
  1325.                 evnt_button(1, 1, 0, &m_x, &m_y, &bstate, &kstate);
  1326.             return;
  1327.         }
  1328.     }
  1329.     else                                                         /* noch nicht angeklickt */
  1330.     {
  1331.         graf_mkstate(&m_x, &m_y, &bstate, &kstate);
  1332.         if (!(bstate & 1))                                /* Immernoch gedrückt -> nichts tun */
  1333.         {
  1334.             bool    re_sel;
  1335.  
  1336.             re_sel = setcmp(new_obj, sel_objs);
  1337.             unclick_window ();                            /* Alle Objekte löschen */
  1338.  
  1339.             /* re_sel ist TRUE, wenn ein Eintrag zum zweiten Mal selektiert wurde
  1340.              * -> wieder deselektieren.
  1341.             */
  1342.             if (!re_sel)
  1343.             {
  1344.                 setincl(sel_objs, y);
  1345.                 sel_window = window;
  1346.             }
  1347.             draw_line(window, y);
  1348.         }
  1349.     }
  1350.     if (breturn == 1 && (bstate & 1))                /* Zieh-Operation */
  1351.     {
  1352.         GRECT        first;
  1353.         int        num_objs, i, obj;
  1354.         WINDOWP    qed_win;
  1355.  
  1356.         graf_mkstate(&m_x, &m_y, &bstate, &kstate);
  1357.         if (!(bstate & 1))
  1358.             return;                                             /* Immernoch gedrückt ? */
  1359.  
  1360.         if (window == sel_window)
  1361.             setcpy(new_obj, sel_objs);
  1362.         num_objs = 0;
  1363.         for (i = 0; i < window->w_height; i++)
  1364.         {
  1365.             if (setin(new_obj, i + (int)window->doc.y))
  1366.             {
  1367.                 if (num_objs == 0)        /* Abmessungen des ersten merken */
  1368.                 {
  1369.                     first.g_x = s->g_x;
  1370.                     first.g_y = s->g_y + (i * font_hcell);
  1371.                     first.g_w = s->g_w;
  1372.                 }
  1373.                 num_objs++;
  1374.             }
  1375.         }
  1376.         obj = drag_box(first.g_x, first.g_y, first.g_w, font_hcell * num_objs, &m_x, &m_y, &bstate, &kstate);
  1377.         qed_win = get_window(obj);
  1378.         if (qed_win)                                                /* eigenes Fenster */
  1379.         {
  1380.             if (qed_win != window && (qed_win->class == CLASS_PROJEKT ||
  1381.                                               qed_win->class == CLASS_EDIT))
  1382.             {
  1383.                 drag_data_size = num_objs;
  1384.                 for (i = 0; i < window->w_height; i++)
  1385.                     if (setin(new_obj, i + (int)window->doc.y))
  1386.                     {
  1387.                         get_prj_line(window->handle, i + (int)window->doc.y, drag_filename);
  1388.                         if (drag_filename[0] == EOS)
  1389.                             break;
  1390.                         if ((kstate & K_ALT) || (qed_win->class == CLASS_PROJEKT))
  1391.                             icon_drag(qed_win->handle, DRAGDROP_FILE);
  1392.                         if (kstate & (K_LSHIFT|K_RSHIFT))
  1393.                             icon_drag(qed_win->handle, DRAGDROP_PATH);
  1394.                     }
  1395.                 drag_data_size = 0;
  1396.             }
  1397.         }
  1398.         else                                                            /* fremdes Fenster */
  1399.         {
  1400.             /* 
  1401.              * Bisher wird immer an den Desktop geschickt,
  1402.              * aber nur, wenn dieser AV_DRAG_ON_WINDOW kann.
  1403.             */
  1404.             if ((av_shell_id >= 0) && (av_shell_status & 512))
  1405.             {        
  1406.                 if (num_objs > 1)
  1407.                 {
  1408.                     drag_data_size = (long)num_objs * sizeof(PATH);
  1409.                     drag_data = (char *)malloc(drag_data_size);
  1410.                     strcpy(drag_data, "");
  1411.                 }
  1412.                 else
  1413.                 {
  1414.                     drag_data_size = 0L;
  1415.                     drag_data = NULL;
  1416.                 }
  1417.                     
  1418.                 i = check_avobj(m_x, m_y);
  1419.                 if (i == 1 || i == 2)                        /* Papierkorb/Shredder */
  1420.                 {
  1421.                     setcpy(sel_objs, new_obj);
  1422.                     do_icon(window->handle+SUB_ICON, DO_DELETE);
  1423.                 }
  1424.                 else
  1425.                 {
  1426.                     for (i=0; i<window->w_height; i++)
  1427.                     {
  1428.                         if (setin(new_obj, i + (int)window->doc.y))
  1429.                         {
  1430.                             get_prj_line(window->handle, i + (int)window->doc.y, drag_filename);
  1431.                             if (drag_filename[0] != EOS)
  1432.                             {
  1433.                                 if (num_objs > 1)
  1434.                                 {
  1435.                                     if (drag_data[0] != EOS)
  1436.                                         strcat(drag_data, " ");
  1437.                                     strcat(drag_data, drag_filename);
  1438.                                 }
  1439.                                 /*    else steht das Arg in drag_filename */
  1440.                             }
  1441.                         }
  1442.                     } /* for */
  1443.     
  1444.                     if (num_objs > 1)
  1445.                         send_avdrag(obj, m_x, m_y, kstate, DRAGDROP_DATA);
  1446.                     else
  1447.                         send_avdrag(obj, m_x, m_y, kstate, DRAGDROP_PATH);
  1448.                 }
  1449.                 if (drag_data_size > 0)
  1450.                 {
  1451.                     free(drag_data);
  1452.                     drag_data_size = 0;
  1453.                 }
  1454.             } /* if av_ */
  1455.         } /* if !my_window */
  1456.     }
  1457.     if (breturn == 2)                                        /* Doppelklick */
  1458.     {
  1459.         unclick_window();
  1460.         sel_window = window;
  1461.         setincl(sel_objs,y);
  1462.         draw_line(window,y);
  1463.         graf_mkstate(&m_x, &m_y, &bstate, &kstate);
  1464.         if (bstate & 1)                                    /* Immernoch gedrückt ? */
  1465.             evnt_button(1, 1, 0, &m_x, &m_y, &bstate, &kstate);
  1466.         do_icon(window->handle + SUB_ICON, DO_OPEN);
  1467.     }
  1468. }
  1469.  
  1470. /***************************************************************************/
  1471.  
  1472. static void wi_unclick (WINDOWP window)
  1473. {
  1474.     SET    help;
  1475.     int    i, max;
  1476.  
  1477.     setcpy(help,sel_objs);
  1478.     setclr(sel_objs);
  1479.     max = setmax(help);
  1480.     for (i=setmin(help); i<=max; i++)
  1481.         if (setin(help,i))
  1482.             draw_line(window,i);
  1483.     set_winfo(window,"");
  1484. }
  1485.  
  1486. /***************************************************************************/
  1487.  
  1488. static void sel_line(WINDOWP window, int line)
  1489. {
  1490.     if (sel_window!=NULL)
  1491.         unclick_window();
  1492.     sel_window = window;
  1493.     setincl(sel_objs,line);
  1494.     draw_line(window,line);
  1495.     line -= (int) window->doc.y;
  1496.     if (line<0)
  1497.         arrow_window(window,WA_UPLINE,-line);
  1498.     else
  1499.     {
  1500.         line -= (window->w_height-1);
  1501.         if (line>0)
  1502.             arrow_window(window,WA_DNLINE,line);
  1503.     }
  1504. }
  1505.  
  1506.  
  1507. static void shift_up(WINDOWP window)
  1508. {
  1509.     int    i;
  1510.  
  1511.     if (window->doc.h == 0)
  1512.         return;
  1513.     if (sel_window == window)
  1514.     {
  1515.         i = setmin(sel_objs);
  1516.         if (i == 0)
  1517.             return ;
  1518.         i -= window->w_height;
  1519.         if (i < 0)
  1520.             i = 0;
  1521.         sel_line(window,i);
  1522.     }
  1523.     else
  1524.         sel_line(window, (int)window->doc.h-1);
  1525. }
  1526.  
  1527. static void shift_down(WINDOWP window)
  1528. {
  1529.     int    i;
  1530.  
  1531.     if (window->doc.h == 0)
  1532.         return ;
  1533.     if (sel_window == window)
  1534.     {
  1535.         i = setmin(sel_objs);
  1536.         if (i == window->doc.h - 1)
  1537.             return ;
  1538.         i += window->w_height;
  1539.         if (i >= window->doc.h)
  1540.             i = (int) window->doc.h - 1;
  1541.         sel_line(window,i);
  1542.     }
  1543.     else
  1544.         sel_line(window,0);
  1545. }
  1546.  
  1547. static bool    wi_key(WINDOWP window, int kstate, int kreturn)
  1548. {
  1549.     bool    erg;
  1550.     int    nkey, i;
  1551.     int    ascii_code;
  1552.     bool    shift, ctrl, alt;
  1553.     
  1554.     /* Key konvertieren */    
  1555.     nkey = gem_to_norm(kstate, kreturn);
  1556.     nkey &= ~(NKF_RESVD|NKF_SHIFT|NKF_CTRL|NKF_CAPS);
  1557.     ascii_code = nkey & 0x00FF;
  1558.     shift = (kstate & (K_RSHIFT|K_LSHIFT)) != 0;
  1559.     ctrl = (kstate & K_CTRL) != 0;
  1560.     alt = (kstate & K_ALT) != 0;
  1561.     
  1562.     /* Damit F-Tasten zum System-Desktop kommen! */
  1563.     if ((kreturn >= 0x3B00 && kreturn <= 0x4400) ||
  1564.          (kreturn >= 0x5400 && kreturn <= 0x5D00))
  1565.         return FALSE;
  1566.  
  1567.     erg = FALSE;
  1568.     if ((nkey & NKF_FUNC) && shift)
  1569.     {
  1570.         nkey &= ~NKF_FUNC;
  1571.         switch (nkey)
  1572.         {
  1573.             case NK_CLRHOME :
  1574.                 v_slider(window, 1000);
  1575.                 sel_line(window, (int)window->doc.h - 1);
  1576.                 erg = TRUE;
  1577.                 break;
  1578.             case NK_UP    :
  1579.                 shift_up(window);
  1580.                 erg = TRUE;
  1581.                 break;
  1582.             case NK_DOWN:
  1583.                 shift_down(window);
  1584.                 erg = TRUE;
  1585.                 break;
  1586.             default:
  1587.                 erg = FALSE;
  1588.                 break;
  1589.         }
  1590.     }
  1591.     else if (nkey & NKF_FUNC)
  1592.     {
  1593.         nkey &= ~NKF_FUNC;
  1594.         switch (nkey)
  1595.         {
  1596.             case NK_RET :
  1597.             case (NK_ENTER|NKF_NUM) :
  1598.                 do_icon(window->handle + SUB_ICON, DO_OPEN);
  1599.                 erg = TRUE;
  1600.                 break;
  1601.             case NK_CLRHOME :
  1602.                 v_slider(window, 0);
  1603.                 sel_line(window,0);
  1604.                 erg = TRUE;
  1605.                 break;
  1606.             case NK_UP :
  1607.                 if (window->doc.h == 0)
  1608.                     break;
  1609.                 if (sel_window == window)
  1610.                 {
  1611.                     i = setmin(sel_objs);
  1612.                     if (i == 0)
  1613.                         break;
  1614.                     i--;
  1615.                     if (i < 0)
  1616.                         i = 0;
  1617.                     sel_line(window,i);
  1618.                 }
  1619.                 else
  1620.                     sel_line(window, (int)window->doc.h - 1);
  1621.                 erg = TRUE;
  1622.                 break;
  1623.             case NK_DOWN:
  1624.                 if (window->doc.h == 0)
  1625.                     break;
  1626.                 if (sel_window == window)
  1627.                 {
  1628.                     i = setmin(sel_objs);
  1629.                     if (i==window->doc.h-1)
  1630.                         break;
  1631.                     i++;
  1632.                     if (i >= window->doc.h)
  1633.                         i = (int) window->doc.h-1;
  1634.                     sel_line(window,i);
  1635.                 }
  1636.                 else
  1637.                     sel_line(window,0);
  1638.                 erg = TRUE;
  1639.                 break;
  1640.             case NK_HELP :
  1641.                 erg = FALSE;                /* DO_HELP wird von key_global verteilt */
  1642.                 break;
  1643.             case NK_M_PGUP:                /* Mac: page up -> shift-up */
  1644.                 shift_up(window);
  1645.                 erg = TRUE;
  1646.                 break;
  1647.             case NK_M_PGDOWN:                /* Mac: page down -> shift-down */
  1648.                 shift_down(window);
  1649.                 erg = TRUE;
  1650.                 break;
  1651.             case NK_M_END:                    /* Mac: end -> shift-home */
  1652.                 v_slider(window, 1000);
  1653.                 sel_line(window, (int)window->doc.h - 1);
  1654.                 erg = TRUE;
  1655.                 break;
  1656.             case NK_DEL :
  1657.                 do_icon(window->handle + SUB_ICON, DO_DELETE);
  1658.                 erg = TRUE;
  1659.                 break;
  1660.             default:
  1661.                 if (!ctrl && !alt && !shift && ascii_code)
  1662.                 {
  1663.                     if (sel_window == window)
  1664.                         unclick_window();
  1665.                     else
  1666.                         set_winfo(window,"");
  1667.                     erg = TRUE;
  1668.                 }
  1669.                 else
  1670.                     erg = FALSE;
  1671.                 break;
  1672.         }
  1673.     }
  1674.     else
  1675.     {
  1676.         int        l;
  1677.         FILENAME name;
  1678.         PATH        str, info;
  1679.         char        asc;
  1680.         
  1681.         /* Auto-Locator */
  1682. /*
  1683.         asc = nkc_toupper(ascii_code);
  1684. */
  1685.         asc =ascii_code;
  1686.         strcpy(info, window->info);
  1687.         l = (int)strlen(info);
  1688.         info[l++] = asc;
  1689.         info[l] = EOS;
  1690.         i = 0;
  1691.         do
  1692.         {
  1693.             get_prj_line(window->handle,i,str);
  1694.             i++;
  1695.             if (str[0] == EOS)
  1696.                 break;
  1697.             file_name(str,name, FALSE);
  1698. /*
  1699.             str_toupper(name);
  1700. */
  1701.         }
  1702.         while (strnicmp(name, info, l) != 0);
  1703.         if (str[0]!=EOS)
  1704.         {
  1705.             sel_line(window,i-1);
  1706.             set_winfo(window,info);
  1707.         }
  1708.         erg = TRUE;
  1709.     }
  1710.     return erg;
  1711. }
  1712.  
  1713. /***************************************************************************/
  1714.  
  1715. static void    wi_snap(WINDOWP window, GRECT *new, int mode)
  1716. {
  1717.     int w, ex, pxy[8];
  1718.  
  1719.     /* zunächst Platz für min. 1+Filename+1 im Fenster */
  1720.     vqt_extent(vdi_handle, "x", pxy);
  1721.     ex = pxy[2] - pxy[0];
  1722.     w = new->g_w;
  1723.     if (w < 14 * ex)
  1724.         w = 14 * ex;
  1725.  
  1726.     /* nun noch Platz für Fenstertitel (1+8+1) */
  1727.     if (w < gl_wchar * 10)
  1728.         w = gl_wchar * 10;
  1729.  
  1730.     new->g_w = w;
  1731. }
  1732.  
  1733.  
  1734. static void wi_iconify(WINDOWP window)
  1735. {
  1736.     TEXTP     t_ptr = get_text(window->handle);
  1737.     FILENAME short_name;
  1738.  
  1739.     if (t_ptr->namenlos)
  1740.         strcpy(short_name, t_ptr->filename);
  1741.     else
  1742.         make_shortpath(t_ptr->filename, short_name, 8);
  1743.     set_wtitle(window, short_name);
  1744. }
  1745.  
  1746.  
  1747. static void wi_uniconify(WINDOWP window)
  1748. {
  1749.     TEXTP     t_ptr = get_text(window->handle);
  1750.     FILENAME name;
  1751.  
  1752.     if (t_ptr->namenlos)
  1753.         strcpy(name, rsc_string(NAMENLOS));
  1754.     else
  1755.         file_name(t_ptr->filename, name, TRUE);
  1756.     set_wtitle(window, name);
  1757. }
  1758.  
  1759. /***************************************************************************/
  1760. /* Info des Objekts                                                                            */
  1761. /***************************************************************************/
  1762.  
  1763. static long     i_len, i_bytes;
  1764. static int        i_anz, i_icon;
  1765.     
  1766. static int count(int icon, int i)
  1767. {
  1768.     PATH    name;
  1769.  
  1770.     i_anz++;
  1771.     get_prj_line(icon, i, name);
  1772.     if ((icon = text_still_loaded(name))>=0)
  1773.     {
  1774.         TEXTP t_ptr;
  1775.  
  1776.         t_ptr = get_text(icon);
  1777.         i_bytes += textring_bytes(&t_ptr->text);
  1778.         i_len += t_ptr->text.lines;
  1779.         return 1;
  1780.     }
  1781.     else
  1782.     {
  1783.         long    b,l;
  1784.         int    antw;
  1785.  
  1786.         antw = infoload(name,&b,&l);
  1787.         i_bytes += b;
  1788.         i_len += l;
  1789.         return (antw == 0) ? 1 : 0;
  1790.     }
  1791. }
  1792.  
  1793. static void info_projekt(int icon)
  1794. {
  1795.     char     str[32], date[11];
  1796.     TEXTP t_ptr = get_text(icon);
  1797.     int    r_anz, i, antw;
  1798.     SET    all;
  1799.     bool    close = FALSE;
  1800.     MDIAL    *dial;
  1801.     
  1802.     set_state(prjinfo, IPRJSCAN, DISABLED, FALSE);
  1803.     i_icon = icon;
  1804.     make_shortpath(t_ptr->filename, str, 30);
  1805.     set_string(prjinfo, PRJNAME, str);         /* Name mit Pfad */
  1806.     if (ist_leer(&t_ptr->text))
  1807.         r_anz = 0;
  1808.     else
  1809.         r_anz = (int)t_ptr->text.lines;
  1810.     set_int(prjinfo, PRJFILES, r_anz);        /* Dateien-Anzahl */
  1811.     set_string(prjinfo, PRJLEN , "??");     /* Länge in Bytes unbekannt */
  1812.     set_string(prjinfo, PRJZEILE , "??");    /* Länge in Zeilen unbekannt */
  1813.     if (t_ptr->namenlos)
  1814.     {
  1815.         strcpy(str, "");
  1816.         strcpy(date, "--");
  1817.     }
  1818.     else
  1819.         file_time (t_ptr->filename, date, str);
  1820.     set_string(prjinfo, PRJDATUM, date);    /* Datum */
  1821.     set_string(prjinfo, PRJZEIT, str);         /* Uhrzeit */
  1822.  
  1823.     dial = open_mdial(prjinfo, 0);
  1824.     if (dial != NULL)
  1825.     {
  1826.         while (!close)
  1827.         {
  1828.             antw = do_mdial(dial) & 0x7fff;
  1829.             switch (antw)
  1830.             {
  1831.                 case IPRJSCAN:
  1832.                     if (ist_leer(&t_ptr->text))
  1833.                         r_anz = 0;
  1834.                     else
  1835.                         r_anz = (int) t_ptr->text.lines;
  1836.                     i_anz = 0;
  1837.                     i_bytes = 0;
  1838.                     i_len = 0;
  1839.                     setclr(all);
  1840.                     for (i = r_anz; (--i)>=0; )
  1841.                         setincl(all, i);
  1842.                     do_for_prj(i_icon, all, count, TRUE);
  1843.                     if (r_anz == i_anz)                                    /* alle durchlaufen */
  1844.                         ltoa(i_bytes, str, 10);
  1845.                     else
  1846.                         str[0] = EOS;
  1847.                     set_string(prjinfo, PRJLEN , str);             /* Länge in Bytes */
  1848.                     if (r_anz == i_anz)
  1849.                         ltoa(i_len, str, 10);
  1850.                     else
  1851.                         str[0] = EOS;
  1852.                     set_string (prjinfo, PRJZEILE , str);        /* Länge in Zeilen */
  1853.                     if (r_anz == i_anz)                                /* alle durchlaufen */
  1854.                         set_state(prjinfo, IPRJSCAN, DISABLED, TRUE);
  1855.                     set_state(prjinfo, IPRJSCAN, SELECTED, FALSE);
  1856.                     redraw_mdobj(dial, 0);
  1857.                     break;
  1858.         
  1859.                 default:
  1860.                     close = TRUE;
  1861.                     break;
  1862.             }
  1863.         }
  1864.         set_state(prjinfo, antw, SELECTED, FALSE);
  1865.         close_mdial(dial);
  1866.     }
  1867. }
  1868.  
  1869. /******************************************************************************/
  1870. /* Default-Projekt                                                                                */
  1871. /******************************************************************************/
  1872.  
  1873. void    open_def_prj(void)
  1874. {
  1875.     if (def_prj_path[0] != EOS && shift_pressed())    /* altes abmelden */
  1876.     {
  1877.         def_prj_path[0] = EOS;
  1878.         def_icon = -1;
  1879.     }
  1880.     else if (def_prj_path[0] != EOS)                 /* bekanntes öffnen */
  1881.         load_projekt(def_prj_path);
  1882.     else
  1883.         select_def_prj();                                 /* nix bekannt, also auswählen */
  1884.     set_def_prj();                                         /* Menü anpassen */
  1885. }
  1886.  
  1887.  
  1888. void    add_to_def(void)
  1889. {
  1890.     WINDOWP w;
  1891.  
  1892.     w = real_top();
  1893.     if (w == NULL)
  1894.         return;
  1895.     if (w->handle != def_icon)
  1896.     {
  1897.         TEXTP t_ptr = get_text(w->handle);
  1898.  
  1899.         if (!t_ptr->namenlos)
  1900.             add_to_projekt(def_icon, t_ptr->filename, TRUE);
  1901.     }
  1902. }
  1903.  
  1904.  
  1905. static void    select_def_prj(void)
  1906. {
  1907.     PATH    name = "";
  1908.  
  1909.     if (select_single(name, "*.qpj", rsc_string(DEFPRJ2STR)))
  1910.     {
  1911.         strcpy(def_prj_path, name);
  1912.         load_projekt(def_prj_path);
  1913.     }
  1914. }
  1915.  
  1916.  
  1917. void set_def_prj(void)
  1918. {
  1919.     FILENAME n = "";
  1920.  
  1921.     if (def_icon == -1 || def_prj_path[0] == EOS)
  1922.     {
  1923.         menu_ienable(menu, MTAKEPRJ, FALSE);
  1924.         menu_icheck(menu, MPROJEKT, FALSE);
  1925.     }
  1926.     else
  1927.     {
  1928.         menu_ienable(menu, MTAKEPRJ, TRUE);
  1929.         menu_icheck(menu, MPROJEKT, TRUE);
  1930.     }
  1931.  
  1932.     /* Name ins Menü eintragen */
  1933.     if (def_prj_path[0] != EOS)
  1934.         file_name(def_prj_path, n, FALSE);
  1935.     else
  1936.         strcpy(n, rsc_string(DEFPRJSTR));
  1937.     fillup_menu(MPROJEKT, n, 2);
  1938. }
  1939.  
  1940. void find_on_disk(void)
  1941. {
  1942.     int    icon;
  1943.     TEXTP    t_ptr;
  1944.     
  1945.     icon = crt_new_prj("");
  1946.     if (icon < 0) 
  1947.         return;
  1948.     if (do_icon(icon, DO_OPEN) < 0)
  1949.     {
  1950.         note(1, 0, NOWINDOW);
  1951.         icon_edit(icon, DO_DELETE);
  1952.     }
  1953.     do_icon(icon, DO_ADD);
  1954.     t_ptr = get_text(icon);
  1955.     if (!t_ptr->moved)            /* nichts gefunden */
  1956.         icon_edit(icon, DO_DELETE);
  1957. }
  1958.  
  1959. /******************************************************************************/
  1960. /* Initialisierung                                                                                */
  1961. /******************************************************************************/
  1962.  
  1963. void init_projekt(void)
  1964. {
  1965.     get_path(df_path, 0);                            /* Aktuellen Pfad holen */
  1966.     prj_type = decl_icon_type(p_icon_test, p_icon_edit, p_icon_exist, p_icon_drag);
  1967.     def_prj_path[0] = EOS;
  1968.     def_icon = -1;
  1969. }
  1970.